<div id="wrap">
	<div class="title"><?php echo $self['title'].' - '.$exist['user']?> <a href="javascript:history.go(-1);">« 返回 </a></div>
	<div class="main">
		<div class="add">
			<p class="tt">添加管理权限</p>
			<select id="zone">
			<?php if($z_list){ ?>
				<optgroup label="版区">
			<?php foreach($z_list as $z_v){?>
				<option value="z:<?php echo $z_v['id']?>"><?php echo $z_v['name']?></option>
			<?php } ?>
				</optgroup>
			<?php } ?>
				<optgroup label="版面">
			<?php foreach($m_list as $m_v){?>
				<option value="m:<?php echo $m_v['id']?>"><?php echo $m_v['name']?></option>
			<?php } ?>
				</optgroup>
			</select>
			<button id="add">添加</button>
		</div>
		<div>
			<p class="tt">已管理列表</p>
			<ul class="add" id="list">
	<?php if($exist['job'] != 3){ ?>
		<?php foreach($list['zone'] as $item1){ ?>
				<li>
					<?php echo $item1['name']?>
				<?php if($admin_data){ ?>
					<span class="btn" id="z:<?php echo $item1['id']?>">移除</span>
				<?php } ?>
				</li>
		<?php }?>
		<?php foreach($list['module'] as $item2){ ?>
				<li>
					<?php echo $item2['name']?>
				<?php if($admin_data || in_array($item2['zid'],$my_zids)){?>
					<span class="btn" id="m:<?php echo $item2['id']?>">移除</span>
				<?php }?>
				</li>
		<?php }?>
		<?php if(!$list['module'] && !$list['zone']){ ?>
				<li>无</li>
		<?php }?>
	<?php }else{ ?>
				<li>全站区、版</li>
	<?php }?>
			</ul>
		</div>
		<div>
		    <p style="margin-bottom:5px">站务拥有管理全站所有的区版的权限</p>
		<?php if(!$admin_data['job']){ ?>
			<?php if($exist['job'] != 3){ ?>
			<button id="set">设为站务</button>
			<?php }else{ ?>
			<button id="set">移除站务</button>
			<?php } ?>
		<?php } ?>
		</div>
	</div>
</div>
<?php echo "<script>let id = {$exist['id']}</script>"?>
</body>
<script type="text/javascript">
	function ajax(url,fun){
	  	let xmlhttp = new XMLHttpRequest();
	  	xmlhttp.onreadystatechange = fun;
		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
	let add = document.getElementById('add');
	add.onclick = function(){
		let zone = document.getElementById('zone').value;
		let arr = zone.split(':');
		if(confirm('您确定要执行这项操作吗?')){
			ajax(`ud.php?type=${arr[0]}&id=${arr[1]}&uid=${id}`,function() {
			    if(this.readyState==4 && this.status==200) {
			    	window.location.reload();
			    }
	  		});
		}
	}
	let list = document.getElementById('list');
	list.onclick = function(e){
		let x_id = e.target.getAttribute('id');
		if(e.target.getAttribute('class') != 'btn' || !x_id){
			return
		}
		let arr = x_id.split(':');
		if(confirm('您确定要移除这项管理权限吗?')){
			ajax(`ud.php?type=${arr[0]}&id=${arr[1]}&uid=${id}`,function() {
			    if(this.readyState==4 && this.status==200) {
			    	window.location.reload();
			    }
	  		});
		}
	}
	let set = document.getElementById('set');
	set.onclick = function(){
		if(confirm('您确定要执行这项操作吗?')){
			ajax(`ud.php?type=5&uid=${id}`,function() {
			    if(this.readyState==4 && this.status==200) {
			    	let {res} = JSON.parse(this.response);
			    	if(res){
						window.location.reload();
			    	}
			    }
	  		});
		}
	}
</script>
</html>